package com.zls.service.impl;

import com.zls.mapper.StageMapper;
import com.zls.page.PageResult;
import com.zls.page.QueryPageBean;
import com.zls.pojo.Developer;
import com.zls.pojo.Stage;
import com.zls.service.StageService;
import com.zls.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class StageServiceImpl implements StageService {
    @Autowired
    private StageMapper stageMapper;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageResult pageResult = new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();//当前页
        Integer pageSize = queryPageBean.getPageSize();//每页大小
        String queryString = queryPageBean.getQueryString();//查询条件
        //total总记录数
        List<Stage> page = stageMapper.findSta((currentPage - 1) * pageSize, pageSize,queryString);
        //rows  当前页的数据
        Long count = stageMapper.count(queryString);
        pageResult.setRows(page);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    public List<Stage> findAll() {
        return stageMapper.findAll();
    }

    @Override
    @Transactional
    public int addStage(Stage stage) {
        stage.setUpdatetime(new Date());
        stage.setSid(UUIDUtils.uuid());
        int i = stageMapper.addStage(stage);
        return i;
    }

    @Override
    @Transactional
    public Stage findBySid(String sid) {
        return stageMapper.findBySid(sid);
    }

    @Override
    @Transactional
    public int editStage(Stage stage) {
        stage.setUpdatetime(new Date());
        int i = stageMapper.updateStage(stage);
        return i;
    }

    @Override
    @Transactional
    public int deleteStage(String sid) {
        int i = stageMapper.deleteStage(sid);
        return i;
    }

    @Override
    public List<Stage> findByPid(int pid) {
        return stageMapper.findByPid(pid);
    }
}
